package com.gui.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gui.entity.R;
import com.gui.hospital.model.Doctor;
import com.gui.hospital.service.DoctorService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:刘舒佳
 * Date:2024/8/23
 */
@RestController
@AllArgsConstructor
@RequestMapping("/doctor")
@CrossOrigin
public class DoctorController {

    private final DoctorService doctorService;

    /**
     * 查询所有医生
     * @return
     */
    @GetMapping
    public List<Doctor> getDoctor(){
        List<Doctor> list = doctorService.list();
        return list;
    }

    /**
     * 通过姓名查找医生
     * @param name
     * @return
     */
    @GetMapping("findByName")
    public List<Doctor> findByName(@RequestParam(value="name",required = false) String name){
        List<Doctor> list = doctorService.findByName(name);
        return list;
    }

    /**
     * 添加医生
     * @param doctor
     * @return
     */
    @PostMapping
    public boolean addDoctor(@RequestBody Doctor doctor){
        boolean save = doctorService.save(doctor);
        return save;
    }

    /**
     * 删除医生
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public boolean deleteDoctor(@PathVariable Integer id){
        boolean remove = doctorService.removeById(id);
        return remove;
    }

    /**
     * 修改医生
     */
    @PutMapping
    public boolean updateDoctor(@RequestBody Doctor doctor){
        boolean update = doctorService.updateById(doctor);
        return update;
    }

    /**
     * 分页查询
     */
    @GetMapping("getPageList/{page}/{size}")
    public Page<Doctor> getPageList(@PathVariable Integer page, @PathVariable Integer size,@RequestBody Doctor doctor){
        Page<Doctor> pageList = doctorService.pageList(page,size,doctor);
        return pageList;
    }

    @GetMapping("findByHdIdAndDate")
    public R findByHdIdAndDate(Integer hdId,String date){
        List<Doctor> list=doctorService.findByHdIdAndDate(hdId,date);
        return new R(list);
    }
}
